var app = new Vue({
	el: '#app',
	data: {
		host:globalData.constParam.url.baseUrl+'/',
		url: {
			GetScrollData:'/api/Index/GetPageIndexForApp', //滚动数据
			getPageNewss: '/api/News/GetPageNewss', //时文推荐
			getPageTodayNewss: '/api/News/GetPageTodayNewss', //今日新闻
		},
		banners: [],//广告图
		modelList:[],	//模块列表
		token: '',
		scrolldata:[],
		todaynews:[],
		timenews:[], //时文
		news_type:0,
		infos:{
			user:globalData.userInfo
		},//用户的所有信息
	},
	mounted: function() {
		var that = this; 
		globalData.getTempToken(function(){
			that.getbanner();
			that.getSubModel();
			that.GetScrollData()
			that.GetTodayNews() //获取今日新闻
			that.getTimeNews()  //获取时文
			$(function(){
				var speed = 20;
				var demo = document.getElementById('demo')
				function Marquee() {
					if(demo.scrollLeft >= $('#marquePic1').width()-1200) {
						demo.scrollLeft = 0;
					} 
					demo.scrollLeft++;
				}
				var MyMar = setInterval(Marquee, speed)
				demo.onmouseover = function() { clearInterval(MyMar); }
				demo.onmouseout = function() {
					MyMar = setInterval(Marquee, speed);
				}
			})
		});		
	},
	methods: {	 
		//获取子模块信息 
		getSubModel:function(){
			var self = this;
			var url = globalData.constParam.url.index_GetSubModels;
			var data={ModelID:"73843dd0457c478481d988856b4cce69"};
			globalData.ajaxPost(url,data,function(res){
				if(res.suc){
					self.modelList=res.data;	
					console.log(self.modelList)
				}else{
					alert(res.msg);
				}
			})
		}, 
		reset_lunbo: function() {
			var mySwiper = new Swiper('.swiper-container', {
				loop: true,
				// 如果需要分页器
				pagination: '.swiper-pagination',
				// 如果需要前进后退按钮
				nextButton: '.swiper-button-next',
				prevButton: '.swiper-button-prev',
				// 如果需要滚动条
				//				scrollbar: '.swiper-scrollbar',var mySwiper = new Swiper('.swiper-container', {
				loop: true,
				// 如果需要分页器
				pagination: '.swiper-pagination',
				// 如果需要前进后退按钮
				nextButton: '.swiper-button-next',
				prevButton: '.swiper-button-prev',
				// 如果需要滚动条
				//				scrollbar: '.swiper-scrollbar',
			})
		},
		getbanner: function() {
			var self = this;
			var url = globalData.constParam.url.index_GetHomeBanner;
			var data={PageIndex:1,PageSize:1000,BannerType:'Home'};
			globalData.ajaxPost(url,data,
			function(d){
				if(d.suc){
					self.banners = d.data;
					setTimeout(function() { 				
						self.reset_lunbo()
					}, 100);
					//隐藏loading
					$(".loading").hide()
				}
			},function(e){});
		    
		},
		viewModelDetail: function(modelID,index) {
			//智能分析需要登录
			if(modelID == 11){
				if(!globalData.userIsLogin(null,true)){
					return;
				}	
			}
			globalData.setStorage('modelID',modelID);
			switch (Number(modelID))
			{
				case 3:
					globalData.utils.setUrl('hight_life.html')
					break;
				case 4:
					globalData.utils.setUrl('overseas_policy.html')
					break;
				case 5:
					globalData.utils.setUrl('International_planning.html')
					break;
				case 6:
					globalData.utils.setUrl('overseas_property.html')
					break;
				case 7:
					globalData.utils.setUrl('overseas_trust.html')
					break;
				case 8:
					globalData.utils.setUrl('tax_planning.html')
					break;
				case 9:
					globalData.utils.setUrl('financial_investment.html')
					break;
				case 10:
					globalData.utils.setUrl('special_solution.html')
					break;
				case 11:									
					globalData.utils.setUrl('intelligent_analysis.html') 
					break;
			}
		},
		goBannerLinkUrl:function(item){
			if(item.LinkUrl){
				globalData.utils.setUrl(item.LinkUrl,null,true)				
			}			
		},
		//获取滚动条数据
		GetScrollData:function(){
			var that = this;
			var data = {pageIndex: 1,pageSize: 100}
			globalData.ajaxPost(this.url.GetScrollData, data, function(res) {
				var d = res.data;
				console.log(d)
				if(d == null)
					return;
				if(res.suc){
					that.scrolldata = []
					$.each(d, function(index,item) {
						if(item.ShowInNews){
							that.scrolldata.push(item)
						}
					});
					$('.title table').css({'min-width':380*that.scrolldata.length+'px'})
				}
			})
		},
		//今日新闻
		GetTodayNews:function(){
			var that = this;
			data = {PageIndex: 1,PageSize: 100,	CateogyId: 1}
			globalData.ajaxPost(this.url.getPageTodayNewss, data, function(res) {
				var d = res.data;
				console.log(d)
				if(res.suc){
					that.todaynews = []
					$.each(d, function(index,item) {
						that.todaynews.push(item)
					});
				}				
			})
		},
		//获取时文
		getTimeNews: function() {
			var that = this;
			var data = { PageIndex: 1, PageSize: 100, CateogyId: 2 }
			globalData.ajaxPost(this.url.getPageNewss, data, function(res) {
				var d = res.data;
				that.timenews = []
				if(res.suc){
					$.each(d, function(index,item) {
						that.timenews.push(item)
					});
					console.log(that.timenews)
				}
			})
		},
		//进入新闻详情页
		go_news_detail: function(newid) {
			var obj = {
				id:newid
			}
			var url = "news_detail.html"
			globalData.utils.setUrl(url,obj)
		}
	},
	filters:{
		cuttime:function(val){0	
			var index = val.indexOf('T')
			var newval = val.replace(/-/g,'/').substring(0,index)
			return newval
		}
	}
})